package cate.game.stat.item;

import cate.common.table.item.hero.row.HeroBaseRow;
import cate.game.GameBody;
import cate.game.role.bag.hero.Hero;
import cp.solution.business.stat.item.HeroLog;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StatHeroBook {

    private Map<Integer, HeroLog> map = new HashMap<>();

    public void read(GameBody game, Hero hero) {
        HeroBaseRow tpl = hero.getTpl(game);
        if(tpl != null) {
            if(tpl.star < 5) {
                return;
            }
            HeroLog l = map.get(tpl.protoId);
            if(l == null) {
                l = new HeroLog();
                l.setProtoId(tpl.protoId);
                l.setHeroName(tpl.foodNameNote);
                map.put(tpl.protoId, l);
            }
            l.setNum(l.getNum() + 1);
            l.setLevelSum(l.getLevelSum() + hero.level);
            if(hero.level > l.getLevelMax()) {
                l.setLevelMax(hero.level);
            }
            l.setStarSum(l.getStarSum() + tpl.star);
            if(tpl.star > l.getStarMax()) {
                l.setStarMax(tpl.star);
            }
        }
    }

    public List<HeroLog> toList() {
        return map.values().stream().collect(Collectors.toList());
    }
}
